/**
 * 
 *深圳市店联电子商务有限公司
 * 
 * */
package com.ruipengkj.view.baseDataView;
/**
 * 说明：
 * 查看个人简历页面
 * @Author： 朱攀
 * @Date：2012-07-30
 */
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.bean.TResume;
import com.ruipengkj.bean.TTexperience;
import com.ruipengkj.commons.BuildSpringApplication;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.commons.util.UUID;
import com.ruipengkj.component.DataPackageComponent;
import com.ruipengkj.component.JLabelJComboBoxComponent;
import com.ruipengkj.component.JLabelJTextAreaComponent;
import com.ruipengkj.component.JLabelJTextFieldComponent;
import com.ruipengkj.model.TTexperienceModel;
import com.ruipengkj.service.TResumeService;
import com.ruipengkj.service.TTexperienceService;
import com.ruipengkj.view.base.BaseDialog;

public class UserResumeDialog extends BaseDialog implements ActionListener{

	private static final long serialVersionUID = 1L;
	
	private JLabelJTextFieldComponent ResumeID;//简历编号
	private JLabelJTextFieldComponent Name;//姓名
	
	private JLabelJComboBoxComponent Sex;//性别   TINYINT1为男 2为女
	//private JLabelJComboBoxComponent Type;//工作性质  TINYINT1为全职 2为兼职
	private JLabelJComboBoxComponent Education;//文化程度TINYINT 10为中学 20为高中 30为中技 40为中专 50 为大专 60 为本科 70为硕士 80为博士
	private JLabelJComboBoxComponent Salary;   //薪资水平TINYINT 1为面议 2为1000-2000 3为2000-3000 4为3000-4000 5为4000-5000 6为5000-6000 7为6000以上
	private JLabelJComboBoxComponent WordYear; // 工作年限  1为 1--5是相对应的工作年限，6为5年以上
	private JLabelJTextFieldComponent Email;// 邮箱 CHAR(6)
	private DataPackageComponent HappenTime;//日期
	private JLabelJTextFieldComponent Phone;//电话
	
	private JLabelJTextFieldComponent School;//毕业学校
	
	private JLabelJTextFieldComponent USubject;//专业
	
	private JPanel jp1;
	private TTexperienceModel tTexperienceModel;
	private JScrollPane tableJsp;
    private JPanel main_jp;
	
	//private JButton sureButton;
	private JButton cancelButton;
	private TResumeService tResumeService;
	private TTexperienceService  tTexperienceService;
	private TResume tResume;

	public boolean isSuccess=false;
	public UserResumeDialog(JFrame jf,String title,boolean b) {
		super(jf, title, b);
		tTexperienceService=BuildSpringApplication.getInstance().getTTexperienceServiceImpl();
		this.setSize(600,750);
		this.setLocationRelativeTo(null);
		this.initComponents();
		this.initListener();
	}
	
	private void initComponents() {
		main_jp=new JPanel();
		BoxLayout boxLayout=new BoxLayout(main_jp, BoxLayout.Y_AXIS);
		main_jp.setLayout(boxLayout);
		//FlowLayout flowLayout=new FlowLayout(FlowLayout.LEFT);
		tTexperienceModel=new TTexperienceModel();
		jp1=new JPanel(new FlowLayout());
		BoxLayout box=new BoxLayout(jp1, BoxLayout.Y_AXIS);
		jp1.setLayout(box);

		ResumeID = new JLabelJTextFieldComponent("简历编号：", 30);
		ResumeID.getText().setText(UUID.GenUUID15());  //设置默认编号
		ResumeID.getText().setEditable(false);   //把文本框设为只读
		Name = new JLabelJTextFieldComponent("姓    名：", 30);
		Sex = new JLabelJComboBoxComponent("性    别：", ApplicationContext.SEX_MAP(),187);  

		School= new JLabelJTextFieldComponent("毕业学校：", 30);
		USubject=new JLabelJTextFieldComponent("专    业：", 30);
		Education=new JLabelJComboBoxComponent("文化程度：",ApplicationContext.JOBEDULEVEL_MAP(),187);
		Salary=new JLabelJComboBoxComponent("薪资水平：",ApplicationContext.SALEVEL_MAP(),187);
		Phone = new JLabelJTextFieldComponent("电    话：", 30);
		Email= new JLabelJTextFieldComponent("邮    箱：", 30);
		HappenTime = new DataPackageComponent("出生日期：", 30);	
		HappenTime.setLayout(new FlowLayout(FlowLayout.LEFT));
		
		
		jp1.add(ResumeID);
		jp1.add(Name);
		jp1.add(Sex);
		jp1.add(School);
		jp1.add(USubject);
		jp1.add(Education);
		jp1.add(Salary);
		
		//jp1.add(WordYear);
		jp1.add(Phone);
		jp1.add(Email);
		jp1.add(HappenTime);
		main_jp.add(jp1);
		
		JPanel down_jp=new JPanel(new FlowLayout());
		cancelButton=new JButton("关闭");
		down_jp.add(cancelButton);
		this.add(main_jp,BorderLayout.CENTER);
		this.add(down_jp,BorderLayout.SOUTH);
	}
	
	private void initListener(){
//		sureButton.addActionListener(this);
//		sureButton.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
		cancelButton.addActionListener(this);
		cancelButton.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
	   if(e.getSource()==cancelButton){//取消按钮
			this.dispose();
		}
	}

	public void showDialog(TResume tr) {
		this.isSuccess=false;
		if(tr!=null){
			ResumeID.getText().setText(tr.getResumeID());
			Name.getText().setText(tr.getName());
			Sex.getBox().setSelectedItem(ApplicationContext.SEX_MAP().get(tr.getSex()));
			School.getText().setText(tr.getSchool());
			USubject.getText().setText(tr.getSubject());
			Education.getBox().setSelectedItem(ApplicationContext.JOBEDULEVEL_MAP().get(tr.getEducation()));
			Salary.getBox().setSelectedItem(ApplicationContext.SALEVEL_MAP().get(tr.getSalary()));
			Phone.getText().setText(tr.getPhone());
			Email.getText().setText(tr.getEMail());
			HappenTime.setDate(tr.getHappenTime());
			
			String resumeID = tr.getResumeID();
			try {
				TResume jl = new TResume();
				jl.setResumeID(resumeID);
				
				PageModel<TTexperience> rs = tTexperienceService.getTTexperienceList(-1, -1, jl);
				List<TTexperience>  es = rs.getResultList();
				TTexperience e = null;
				//-----------------------------工作经验
//				
				JLabelJTextFieldComponent STime;//工作开始日期
				JLabelJTextFieldComponent ETime;//离职日期
				JLabelJTextFieldComponent Company;//公司名称
				JLabelJTextFieldComponent Job;//职位
				JLabelJTextAreaComponent  Des;	//描述
				JLabel labelTxt ;  //标题
				
				
				FlowLayout flowLayout=new FlowLayout(FlowLayout.LEFT);
				JPanel jp = new JPanel(); 
				BoxLayout box=new BoxLayout(jp, BoxLayout.Y_AXIS);
				jp.setLayout(box);

			
				tableJsp=new JScrollPane(jp);
				tableJsp.setViewportView(jp);
				tableJsp.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 
				main_jp.add(tableJsp);
				for(int i = 0; i < es.size(); i ++)
				{
					e = es.get(i);
					String t="";
					if(i==0){
						t="工作经验一：";
					}else if(i==1){
						t="工作经验二：";
					}
					else if(i==2){
						t="工作经验三：";
					}
					else if(i==3){
						t="工作经验四：";
					}
					else if(i==4){
						t="工作经验五：";
					}else if(i==5){
						t="工作经验六：";
					}
					else if(i==6){
						t="工作经验七：";
					}
					else if(i==7){
						t="工作经验八：";
					}
					else if(i==8){
						t="工作经验九：";
					}
					
					Des=	new JLabelJTextAreaComponent("简    介：", 60, 10);
					Company= new JLabelJTextFieldComponent("公司名称：", 30);
					Job= new JLabelJTextFieldComponent("职位名称：", 30);
					STime = new JLabelJTextFieldComponent("入职日期：",30);	
					ETime = new JLabelJTextFieldComponent("离职日期：",30);	
					 labelTxt = new JLabel(t);
					STime.getText().setText(e.getStartDate()+"");
					ETime.getText().setText(e.getEndDate()+"");
					ETime.getText().setEditable(false);
					STime.getText().setEditable(false);
					Company.getText().setText(e.getCompany());
					Job.getText().setText(e.getJob());
					Des.getArea().setText(e.getDes());
					jp.add(labelTxt);
					jp.add(STime);
					jp.add(ETime);
					jp.add(Company);
					jp.add(Job);
					jp.add(Des);
				}
				main_jp.updateUI();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
		this.setVisible(true);
	}
	
	
}
